package com.oa.pm.controller;

import com.joneying.common.web.response.Resp;
import com.oa.core.utils.request.RFormParam;
import com.oa.pm.dto.EmploymentRecordListDTO;
import com.oa.pm.dto.InductionTrainingDTO;
import com.oa.pm.entity.EmploymentRecord;
import com.oa.pm.service.IEmploymentRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author syb123
 * @since 2019-01-22
 */
@RestController
@RequestMapping("/employmentRecord")
@Api(description = "任职记录表模块")
public class EmploymentRecordController extends BaseController {

    private final IEmploymentRecordService employmentRecordService;

    @Autowired
    public EmploymentRecordController(IEmploymentRecordService employmentRecordService) {
        this.employmentRecordService = employmentRecordService;
    }

    @GetMapping("/list")
    @CommonController
    @Description("查询任职记录列表")
    @ApiOperation(value = "查询任职记录列表")
    public Resp findEmploymentRecordList(EmploymentRecordListDTO employmentRecordListDTO) {
        return new Resp().success(employmentRecordService.findEmploymentRecordList(employmentRecordListDTO));
    }

    @GetMapping("/{id}")
    @CommonController
    @Description("根据id")
    @ApiOperation(value = "根据ID查询")
    public Resp findById(@ApiParam("id") @PathVariable String id) {
        return new Resp().success(employmentRecordService.selectById(id));
    }

    /**
     * 新增
     *
     * @param employmentRecord EmploymentRecord
     * @return Resp
     */
    @PostMapping("")
    @CommonController
    @Description("新增")
    @ApiOperation(value = "新增")
    public Resp add(@ApiParam(value = "任职记录表对象") @RequestBody(required = false) EmploymentRecord employmentRecord) {
        if (employmentRecordService.insert(employmentRecord)) {
            return new Resp().success();
        } else {
            return new Resp().failure();
        }
    }

    /**
     * 根据Id修改
     *
     * @param employmentRecord EmploymentRecord
     * @return Resp
     */
    @PutMapping("")
    @CommonController
    @Description("根据id修改")
    @ApiOperation(value = "根据id修改")
    public Resp update(@ApiParam(value = "任职记录表对象") @RequestBody(required = false) EmploymentRecord employmentRecord) {
        if (employmentRecordService.updateById(employmentRecord)) {
            return new Resp().success();
        } else {
            return new Resp().failure();
        }
    }

    /**
     * 根据Id删除
     *
     * @param id id
     * @return Resp
     */
    @DeleteMapping("/{id}")
    @CommonController
    @Description("根据id删除")
    @ApiOperation(value = "根据id删除")
    public Resp delete(@ApiParam(value = "id", required = true) @PathVariable("id") String id) {
        EmploymentRecord employmentRecord = employmentRecordService.selectById(id);
        if (employmentRecord != null && employmentRecord.getIsDeleted() == 2) {
            employmentRecord.setIsDeleted(1);
            if (employmentRecordService.updateById(employmentRecord)) {
                return new Resp().success();
            }
            return new Resp().failure();
        }
        return new Resp().failure();
    }

}